package com.zwr.sheller.shop.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.common.WQQBusinessException;
import com.zwr.sheller.core.pojo.NavigationBar;
import com.zwr.sheller.core.pojo.Store;
import com.zwr.sheller.shop.service.NavigationBarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: 18032
 * @Date: 11:35 2022/1/6
 */
@CrossOrigin
@RestController
@RequestMapping("/navigationBar")
@Api(tags = "导航栏设置")
public class NavigationBarController {

    @Autowired
    NavigationBarService navigationBarService;

    @PostMapping("/selectAllBars")
    @ApiOperation("店铺设置:点击显示所有店铺导航拦")
    public Map<String, Object> selectAllBars() {
        List<NavigationBar> navigationBars = navigationBarService.selectAllBars();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data", navigationBars);
        return jsonResult.getMap();
    }


    @PostMapping("/selectAllItems")
    @ApiOperation("导航栏设置:导航添加中,点击选择所有的分类")
    public Map<String, Object> selectAllItems() {
        List<Map<String, Object>> list = navigationBarService.selectAllItemName();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data", list);
        return jsonResult.getMap();
    }

    @PostMapping("/addBar")
    @ApiOperation("店铺设置:点击添加店铺导航拦")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "navigationBarOrder", value = "导航排序", dataType = "Long",required = false),
            @ApiImplicitParam(name = "itemId", value = "分类id", dataType = "Long"),
            @ApiImplicitParam(name = "navigationBarIsSee", value = "是否显示导航栏", dataType = "Boolean",required = false)
    })
    public Map<String, Object> addBar(NavigationBar navigationBar) throws WQQBusinessException {
        Integer integer = navigationBarService.addBar(navigationBar);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("msg", "添加成功");
        return jsonResult.getMap();
    }


    @PostMapping("/updateBar")
    @ApiOperation("店铺设置:点击修改店铺导航拦")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "navigationBarId",value = "导航栏id",dataType = "Long"),
            @ApiImplicitParam(name = "navigationBarOrder", value = "导航排序", dataType = "Long",required = false),
            @ApiImplicitParam(name = "itemId", value = "分类id", dataType = "Long"),
            @ApiImplicitParam(name = "navigationBarIsSee", value = "是否显示导航栏", dataType = "Boolean",required = false)
    })
    public Map<String, Object> updateBar(NavigationBar navigationBar) throws WQQBusinessException {
        Integer integer = navigationBarService.updateBar(navigationBar);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("msg", "修改成功");
        return jsonResult.getMap();
    }

    @PostMapping("/deleteBar")
    @ApiOperation("店铺设置:点击删除店铺导航拦")
    @ApiImplicitParam(name = "barId", value = "导航id", dataType = "Long")
    public Map<String, Object> deleteBar(Long barId) throws WQQBusinessException {
        Integer integer = navigationBarService.deleteBar(barId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("msg", "删除成功");
        return jsonResult.getMap();
    }
}
